<template>
    <div>
        <h1>显示</h1>
       
        <table class="table table-bordered">
            <tbody>
               <tr>
                <td>会员id</td>
                <td>会员编号</td>
                <td>会员手机号</td>
                <td>会员姓名</td>
                <td>身份证号码</td>
                <td>出生日期</td>
                <td>积分</td>
                <td>余额</td>
                <td>会员等级</td>
                <td>会员性别</td>
                <td>会员爱好</td>
                <td>会员简介</td>
                <td>证件类型</td>
                <td>操作</td>
               </tr>
                <tr :key="item.id" v-for="item in list">
                <td>{{item.id}}</td>
                <td>{{item.memberCode}}</td>
                <td>{{item.tel}}</td>
                <td>{{item.userName}}</td>
                <td>{{item.card}}</td>
                <td>{{moment(item.birthday).format('YYYY-MM-DD')}}</td>
                <td>{{item.score}}</td>
                <td>{{item.money}}</td>
                <td>{{item.memberName}}</td>
                <td>{{item.gender==true?'男':'女'}}</td>
                <td>{{item.likes}}</td>
                <td>{{item.desc}}</td>
                <td>{{item.cardType}}</td>
                <td><input type="button" class="btn btn-primary" value="删除" @click="del(item.id)" >
                <input type="button" class="btn btn-primary" value="修改" @click="upd(item.id)" >
                </td>
               </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import axios from 'axios'
import moment from 'moment'
import {ref,reactive,onMounted} from 'vue';
import {useRouter} from 'vue-router'
const router=useRouter();
let info:any=ref({
   userName:'',
   tel:'',
   levelId:''
})
onMounted(()=>
{
    getlist();
    show();
})

let getselect:any=ref([])
const getlist=()=>
{
    axios({
        url:"http://localhost:5237/api/Member/GetMemberList",
        method:"get",
        
    })
    .then((res)=>
    {
        console.log(res);
        getselect.value=res.data;
    })
    .catch((err)=>
    {
        console.log(err);
    })
}
let list:any=ref([])
const show=()=>
{
    
    axios({
        url:"http://localhost:5237/api/Member/GetMembersList",
        method:"get",
        data:info
    })
    .then((res)=>
    {
        console.log(res);
        list.value=res.data;
        
    })
    .catch((err)=>
    {
        console.log(err);
    })
}
const del=(id:any)=>
{
    console.log(id);
    var f=confirm('请问您确认删除吗?');
    if(f)
    {
        axios({
        url:"http://localhost:5237/api/Member/DelMemberItem",
        method:"delete",
        params:{
            id:id
        }
    })
    .then((res)=>
    {
        console.log(res);
       
        if(res.data>0)
        {
            alert("删除成功");
            router.push("/memberShow");
            return;
        }
        else
        {
            alert("删除失败");
            return;
        }
    })
    .catch((err)=>
    {
        console.log(err);
    })
    }
    
}
const upd=(id:any)=>
{
    router.push({
        path:'/memberUpdate',
        query:{
            id:id
        }
    });
}
</script>

<style scoped>

</style>